﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;

namespace CCManger.WinServer.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public MainWindowViewModel(IRegionManager regionManager)
        {
            if (_regionManager == null)
            {
                _regionManager = regionManager;
                NavigateCommand = new DelegateCommand<string>(Navigate);
                regionManager.RegisterViewWithRegion("LeftRegion", typeof(CCManger.WinServer.Views.LeftRegion));
                regionManager.RegisterViewWithRegion("MainRegion", typeof(CCManger.ModuleSocket.Views.MainSocket));
                regionManager.RegisterViewWithRegion("MainRegion", typeof(CCManger.WinServer.Views.Server));
            }
        }

        #region 界面相关属性

        private string _title = "服务管理";

        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        private bool _IsLeftDrawerOpen = false;

        /// <summary>
        /// 是否打开左侧导航
        /// </summary>
        public bool IsLeftDrawerOpen
        {
            get { return _IsLeftDrawerOpen; }
            set { SetProperty(ref _IsLeftDrawerOpen, value); }
        }

        /// <summary>
        /// 导航命令
        /// </summary>
        public DelegateCommand<string> NavigateCommand { get; private set; }

        private void Navigate(string navigatePath)
        {
            if (navigatePath != null)
            {
                _regionManager.RequestNavigate("MainRegion", navigatePath);
                IsLeftDrawerOpen = false;
            }
        }

        #endregion 界面相关属性

        #region 弹出对话框

        private DelegateCommand _AboutDialogCommand;

        public DelegateCommand AboutDialogCommand =>
            _AboutDialogCommand ?? (_AboutDialogCommand = new DelegateCommand(ExecuteboutDialogCommand));

        private async void ExecuteboutDialogCommand()
        {
            var view = new Views.About();
            var result = await DialogHost.Show(view, "RootDialog");
        }

        #endregion 弹出对话框
    }
}